package com.moneyhelper.upms.mapper;

import com.moneyhelper.common.mapper.CommonMapper;
import com.moneyhelper.upms.entity.SysMenu;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author： ygl
 * @date： 2019/07/07
 * @Description：
 */
public interface SysMenuMapper extends CommonMapper<SysMenu> {

	/**
	 * 通过角色id查询有用的菜单
	 * @param roleId
	 * @return
	 */
	@Select("select m.* from sys_role_menu rm inner join sys_menu m" +
			" on rm.menu_id = m.id and rm.role_id = #{roleId}")
	List<SysMenu> selectHandleMenusByRoleId(String roleId);

	/**
	 * 查询用户有权限的菜单
	 * @param userId
	 * @return
	 */
	@Select("select m.* from sys_role_menu rm inner join sys_menu m" +
			" on rm.menu_id = m.id and rm.role_id in(" +
			" select role_id from sys_user_role where user_id = #{userId}" +
			")")
	List<SysMenu> getMenuByUserId(String userId);
}
